#include "frmScene.h"
#include "GameSystemManager.h"
#include "GameSceneManager.h"
#include "GUISystem.h"
#include "SkyGenerator.h"

frmScene::frmScene() {
	subscribeEvents();
	setup();
}
frmScene::~frmScene() {

}

void frmScene::subscribeEvents() {

	////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//Subsribe GUI Objects events
	CEGUI::Editbox* txtFogStart = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtFogLineStart");
	txtFogStart->subscribeEvent(CEGUI::Editbox::EventTextChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneFogStart_change,this));

	CEGUI::Editbox* txtFogEnd = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtFogLineEnd");
	txtFogEnd->subscribeEvent(CEGUI::Editbox::EventTextChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneFogEnd_change,this));

	CEGUI::Editbox* txtSkyBoxDistance = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtSkyBoxDistance");
	txtSkyBoxDistance->subscribeEvent(CEGUI::Editbox::EventTextChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneSkyBoxDistance_change,this));

	CEGUI::Combobox* cmbSkyBox = (CEGUI::Combobox*) CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbSkybox");
	cmbSkyBox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted,CEGUI::Event::Subscriber(&frmScene::evtSceneSkyBoxList_change,this));

	CEGUI::Window* optSceneOptSkyBox = CEGUI::WindowManager::getSingleton().getWindow("Scene/optSkybox");
	optSceneOptSkyBox->subscribeEvent(CEGUI::RadioButton::EventMouseButtonUp,CEGUI::Event::Subscriber(&frmScene::evtSceneOptSkyBox_change,this));

	CEGUI::Window* optSceneOptCaelum = CEGUI::WindowManager::getSingleton().getWindow("Scene/optCaelum");
	optSceneOptCaelum->subscribeEvent(CEGUI::RadioButton::EventMouseButtonUp,CEGUI::Event::Subscriber(&frmScene::evtSceneOptCaelum_change,this));

	CEGUI::Editbox* txtFOVy = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/FOVy");
	txtFOVy->subscribeEvent(CEGUI::Editbox::EventTextChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneFOVy_change,this));

	CEGUI::Editbox* txtNearClip = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtNearClipDistance");
	txtNearClip->subscribeEvent(CEGUI::Editbox::EventTextChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneNearClip_change,this));

	CEGUI::Editbox* txtAspectRatio = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtAspectRatio");
	txtAspectRatio->subscribeEvent(CEGUI::Editbox::EventTextChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneAspectRatio_change,this));

	CEGUI::Editbox* txtFarClip = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtFarClipDistance");
	txtFarClip->subscribeEvent(CEGUI::Editbox::EventTextChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneFarClip_change,this));

	CEGUI::Window* btnActivateSky = CEGUI::WindowManager::getSingleton().getWindow("Scene/btnSky");
	btnActivateSky->subscribeEvent(CEGUI::PushButton::EventClicked,CEGUI::Event::Subscriber(&frmScene::evtSceneActivateSky_click,this));

	CEGUI::Window* sldRed = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldRed");
	sldRed->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneBackgroundRed_change,this));

	CEGUI::Window* sldGreen = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldGreen");
	sldGreen->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneBackgroundGreen_change,this));

	CEGUI::Window* sldBlue = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldBlue");
	sldBlue->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneBackgroundBlue_change,this));

	CEGUI::Combobox* mFogType = (CEGUI::Combobox*) CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbFogType");
	mFogType->subscribeEvent(CEGUI::Combobox::EventListSelectionChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneFogType_change,this));

	CEGUI::Combobox* mProjType = (CEGUI::Combobox*) CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbProjType");
	mProjType->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted,CEGUI::Event::Subscriber(&frmScene::evtSceneProjectionType_change,this));

	CEGUI::Window* sldFogDensity = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogDensity");
	sldFogDensity->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneFogDensity_change,this));

	CEGUI::Window* sldFogColorRed = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogRed");
	sldFogColorRed->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneFogColorRed_change,this));

	CEGUI::Window* sldFogColorGreen = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogGreen");
	sldFogColorGreen->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneFogColorGreen_change,this));

	CEGUI::Window* sldFogColorBlue = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogBlue");
	sldFogColorBlue->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneFogColorBlue_change,this));

	CEGUI::Window* sldAmbientLightRed = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldAmbientLightRed");
	sldAmbientLightRed->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneAmbientLightRed_change,this));

	CEGUI::Window* sldAmbientLightGreen = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldAmbientLightGreen");
	sldAmbientLightGreen->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneAmbientLightGreen_change,this));

	CEGUI::Window* sldAmbientLightBlue = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldAmbientLightBlue");
	sldAmbientLightBlue->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneAmbientLightBlue_change,this));

	CEGUI::Window* sldDiffuseLightRed = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDiffuseLightRed");
	sldDiffuseLightRed->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneDiffuseLightRed_change,this));

	CEGUI::Window* sldDiffuseLightGreen = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDiffuseLightGreen");
	sldDiffuseLightGreen->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneDiffuseLightGreen_change,this));

	CEGUI::Window* sldDiffuseLightBlue = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDiffuseLightBlue");
	sldDiffuseLightBlue->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneDiffuseLightBlue_change,this));

	CEGUI::Window* sldSpecularLightRed = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldSpecularLightRed");
	sldSpecularLightRed->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneSpecularLightRed_change,this));

	CEGUI::Window* sldSpecularLightGreen = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldSpecularLightGreen");
	sldSpecularLightGreen->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneSpecularLightGreen_change,this));

	CEGUI::Window* sldSpecularLightBlue = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldSpecularLightBlue");
	sldSpecularLightBlue->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneSpecularLightBlue_change,this));

	CEGUI::Window* sldDayNightCycle = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDayNightCycle");
	sldDayNightCycle->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneDayNightCycle_change,this));

	CEGUI::Window* sldCloudsSpeed = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudSpeed");
	sldCloudsSpeed->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneCloudsSpeed_change,this));

	CEGUI::Window* sldCloudsCover = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudsCover");
	sldCloudsCover->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneCloudsCover_change,this));

	CEGUI::Window* sldCloudsBendTime = CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudBendTime");
	sldCloudsBendTime->subscribeEvent(CEGUI::Slider::EventValueChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneCloudsBendTime_change,this));

	CEGUI::Checkbox* chkManagedLight = (CEGUI::Checkbox*) CEGUI::WindowManager::getSingleton().getWindow("Scene/chkLightManaged");
	chkManagedLight->subscribeEvent(CEGUI::Checkbox::EventCheckStateChanged,CEGUI::Event::Subscriber(&frmScene::evtSceneManageLight_click,this));

	CEGUI::Window* wndObjectsClose = CEGUI::WindowManager::getSingleton().getWindow("Scene");
	wndObjectsClose->subscribeEvent(CEGUI::FrameWindow::EventCloseClicked,CEGUI::Event::Subscriber(&frmScene::evtSceneClose_click,this));

}

void frmScene::setup() {
	CEGUI::Window* w = CEGUI::WindowManager::getSingleton().getWindow("Scene");
	w->setVisible(true);

	CEGUI::Slider* sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogDensity");
	sld->setMaxValue(0.01);
	sld->setCurrentValue(0.008);
	CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblRed11");
	lbl->setText("0.008");

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldRed");
	sld->setMaxValue(1);
	sld->setCurrentValue(0);
	lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblRed");
	lbl->setText("0");

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldGreen");
	sld->setMaxValue(1);
	sld->setCurrentValue(0);
	lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblGreen");
	lbl->setText("0");

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldBlue");
	sld->setMaxValue(1);
	sld->setCurrentValue(0);
	lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblBlue");
	lbl->setText("0");

	CEGUI::Combobox* cmbProj = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbProjType");
	const CEGUI::Image* sel_img = &CEGUI::ImagesetManager::getSingleton().getImageset("TaharezLook")->getImage("MultiListSelectionBrush");
	CEGUI::ListboxTextItem* itm5;
	itm5 = new CEGUI::ListboxTextItem("ORTHOGRAPHIC", 0);
	itm5->setSelectionBrushImage(sel_img);
	cmbProj->addItem(itm5);
	
	cmbProj = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbProjType");
	sel_img = &CEGUI::ImagesetManager::getSingleton().getImageset("TaharezLook")->getImage("MultiListSelectionBrush");
	CEGUI::ListboxTextItem* itm6;
	itm6 = new CEGUI::ListboxTextItem("PERSPECTIVE", 1);
	itm6->setSelectionBrushImage(sel_img);
	cmbProj->addItem(itm6);
	
	CEGUI::Combobox* cmb = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbFogType");

	sel_img = &CEGUI::ImagesetManager::getSingleton().getImageset("TaharezLook")->getImage("MultiListSelectionBrush");
	CEGUI::ListboxTextItem* itm1;
	itm1 = new CEGUI::ListboxTextItem("FOG_EXP", 1);
    itm1->setSelectionBrushImage(sel_img);
    cmb->addItem(itm1);
	
	CEGUI::ListboxTextItem* itm2;
	itm2 = new CEGUI::ListboxTextItem("FOG_EXP2", 2);
    itm2->setSelectionBrushImage(sel_img);
    cmb->addItem(itm2);

	CEGUI::ListboxTextItem* itm3;
	itm3 = new CEGUI::ListboxTextItem("FOG_LINEAR", 3);
    itm3->setSelectionBrushImage(sel_img);
    cmb->addItem(itm3);

	CEGUI::ListboxTextItem* itm4;
	itm4 = new CEGUI::ListboxTextItem("FOG_NONE", 0);
    itm4->setSelectionBrushImage(sel_img);
    cmb->addItem(itm4);


	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDayNightCycle");
	sld->setMaxValue(400);
	sld->setCurrentValue(1);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudSpeed");
	sld->setMaxValue(0.00005);
	sld->setCurrentValue(0.000005);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudsCover");
	sld->setMaxValue(1);
	sld->setCurrentValue(0.5);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudBendTime");
	sld->setMaxValue(48);
	sld->setCurrentValue(24);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldAmbientLightRed");
	sld->setMaxValue(5);
	sld->setCurrentValue(0.5);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldAmbientLightGreen");
	sld->setMaxValue(5);
	sld->setCurrentValue(0.5);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldAmbientLightBlue");
	sld->setMaxValue(5);
	sld->setCurrentValue(0.5);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDiffuseLightRed");
	sld->setMaxValue(5);
	sld->setCurrentValue(3.0);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDiffuseLightGreen");
	sld->setMaxValue(5);
	sld->setCurrentValue(3.0);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDiffuseLightBlue");
	sld->setMaxValue(5);
	sld->setCurrentValue(2.7);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldSpecularLightRed");
	sld->setMaxValue(5.0);
	sld->setCurrentValue(5.0);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldSpecularLightGreen");
	sld->setMaxValue(5.0);
	sld->setCurrentValue(5.0);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldSpecularLightBlue");
	sld->setMaxValue(5.0);
	sld->setCurrentValue(5.0);

	populateSkyBoxCombo();

/*
	cmb->resetList();
	CEGUI::ListboxItem *lb1; // = new CEGUI::ListboxItem(); //"FOG_EXP"
	lb1->setText("FOG_EXP");
	cmb->addItem(lb1);
	CEGUI::ListboxItem *lb2; // = new CEGUI::ListboxItem("FOG_EXP2");
	lb1->setText("FOG_EXP2");
	cmb->addItem(lb2);
	CEGUI::ListboxItem *lb3; // = new CEGUI::ListboxItem("FOG_LINEAR");
	lb1->setText("FOG_LINEAR");
	cmb->addItem(lb3);
	CEGUI::ListboxItem *lb4; // = new CEGUI::ListboxItem("FOG_NONE");
	lb1->setText("FOG_NONE");
	cmb->addItem(lb4);
*/

}


void frmScene::fillGUIFromConfig() {
	
	//CEGUI::Window* w = CEGUI::WindowManager::getSingleton().getWindow("Scene");
	//w->setVisible(true);

	//Background Color slider
	CEGUI::Slider* sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldRed");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.backgroundColour.r);
	CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblRed");
	lbl->setText(Ogre::StringConverter::toString(sky_config.backgroundColour.r).c_str());

	//Background Color slider
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldGreen");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.backgroundColour.g);
	lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblGreen");
	lbl->setText(Ogre::StringConverter::toString(sky_config.backgroundColour.g).c_str());

	//Background Color slider
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldBlue");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.backgroundColour.b);
	lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblBlue");
	lbl->setText(Ogre::StringConverter::toString(sky_config.backgroundColour.b).c_str());

	//Ambient Light
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldAmbientLightRed");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.ambientLight.r);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldAmbientLightGreen");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.ambientLight.g);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldAmbientLightBlue");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.ambientLight.b);

	//Diffuse Light
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDiffuseLightRed");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.diffuseLight.r);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDiffuseLightGreen");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.diffuseLight.g);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDiffuseLightBlue");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.diffuseLight.b);

	//Specular Light
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldSpecularLightRed");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.specularLight.r);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldSpecularLightGreen");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.specularLight.g);
	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldSpecularLightBlue");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.specularLight.b);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDayNightCycle");
	sld->setMaxValue(400);
	sld->setCurrentValue(sky_config.timeScale);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudSpeed");
	sld->setMaxValue(0.00005);
	sld->setCurrentValue(sky_config.cloudsSpeed);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudsCover");
	sld->setMaxValue(1);
	sld->setCurrentValue(sky_config.cloudsCover);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudBendTime");
	sld->setMaxValue(48);
	sld->setCurrentValue(sky_config.cloudsBendTime);

	CEGUI::Combobox* cmbProj = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbProjType");
	CEGUI::Editbox* txtNearClip = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtNearClipDistance");
	CEGUI::Editbox* txtFarClip = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtFarClipDistance");
	CEGUI::Editbox* txtFOVy = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/FOVy");
	CEGUI::Editbox* txtAspectRatio = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtAspectRatio");

	if(sky_config.ProjType == PT_ORTHOGRAPHIC)
		cmbProj->setText("ORTHOGRAPHIC");
	if(sky_config.ProjType == PT_PERSPECTIVE)
		cmbProj->setText("PERSPECTIVE");

	std::string nc = Ogre::StringConverter::toString(sky_config.NearClip);
	std::string fc = Ogre::StringConverter::toString(sky_config.FarClip);

	txtNearClip->setText(nc);
	txtFarClip->setText(fc);
	
	//Ogre::Radian FOVy = Radian(Degree(Ogre::StringConverter::parseReal(sky_config.FOVy)));
	txtFOVy->setText(Ogre::StringConverter::toString(sky_config.FOVy).c_str());
	
	txtAspectRatio->setText(Ogre::StringConverter::toString(sky_config.AspectRatio).c_str());

	//Fog Config
	CEGUI::Combobox* cmbFogType = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbFogType");
	CEGUI::Editbox* txtLineStart = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtFogLineStart");
	CEGUI::Editbox* txtLineEnd = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtFogLineEnd");
	
	if(sky_config.FogType == 0)
		cmbFogType->setText("FOG_NONE");
	if(sky_config.FogType == 1)
		cmbFogType->setText("FOG_EXP");
	if(sky_config.FogType == 2)
		cmbFogType->setText("FOG_EXP2");
	if(sky_config.FogType == 3)
		cmbFogType->setText("FOG_LINEAR");

	txtLineStart->setText(Ogre::StringConverter::toString(sky_config.FogLineStart).c_str());
	txtLineEnd->setText(Ogre::StringConverter::toString(sky_config.FogLineEnd).c_str());

	CEGUI::Slider* sldFogDens = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogDensity");
	sldFogDens->setMaxValue(0.01);
	sldFogDens->setCurrentValue(sky_config.FogDensity);
	lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblRed11");
	lbl->setText(Ogre::StringConverter::toString(sky_config.FogDensity).c_str());

	CEGUI::Slider* sldFogColorRed = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogRed");
	sldFogColorRed->setMaxValue(1);
	sldFogColorRed->setCurrentValue(sky_config.FogColour.r);
	CEGUI::Slider* sldFogColorGreen = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogGreen");
	sldFogColorGreen->setMaxValue(1);
	sldFogColorGreen->setCurrentValue(sky_config.FogColour.g);
	CEGUI::Slider* sldFogColorBlue = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogBlue");
	sldFogColorBlue->setMaxValue(1);
	sldFogColorBlue->setCurrentValue(sky_config.FogColour.b);


	//Skybox
	CEGUI::Combobox* cmbSkybox = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbSkybox");
	cmbSkybox->setText(sky_config.skyBoxName);

	CEGUI::RadioButton* radSkybox = (CEGUI::RadioButton*) (CEGUI::WindowManager::getSingleton().getWindow("Scene/optSkybox"));
	CEGUI::RadioButton* radCaelum = (CEGUI::RadioButton*) (CEGUI::WindowManager::getSingleton().getWindow("Scene/optCaelum"));
	if(sky_config.skyMode == "Caelum")
		radCaelum->setSelected(true);
	if(sky_config.skyMode == "Skybox")
		radSkybox->setSelected(true);

	CEGUI::Editbox* txtSkyDist = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtSkyBoxDistance");
	txtSkyDist->setText(Ogre::StringConverter::toString(sky_config.skyBoxDistance).c_str());

	/*
	CEGUI::Combobox* cmbProj = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbProjType");
	const CEGUI::Image* sel_img = &CEGUI::ImagesetManager::getSingleton().getImageset("TaharezLook")->getImage("MultiListSelectionBrush");
	CEGUI::ListboxTextItem* itm5;
	itm5 = new CEGUI::ListboxTextItem("ORTHOGRAPHIC", 0);
	itm5->setSelectionBrushImage(sel_img);
	cmbProj->addItem(itm5);

	cmbProj = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbProjType");
	sel_img = &CEGUI::ImagesetManager::getSingleton().getImageset("TaharezLook")->getImage("MultiListSelectionBrush");
	CEGUI::ListboxTextItem* itm6;
	itm6 = new CEGUI::ListboxTextItem("PERSPECTIVE", 1);
	itm6->setSelectionBrushImage(sel_img);
	cmbProj->addItem(itm6);

	CEGUI::Combobox* cmb = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbFogType");

	sel_img = &CEGUI::ImagesetManager::getSingleton().getImageset("TaharezLook")->getImage("MultiListSelectionBrush");
	CEGUI::ListboxTextItem* itm1;
	itm1 = new CEGUI::ListboxTextItem("FOG_EXP", 1);
	itm1->setSelectionBrushImage(sel_img);
	cmb->addItem(itm1);

	CEGUI::ListboxTextItem* itm2;
	itm2 = new CEGUI::ListboxTextItem("FOG_EXP2", 2);
	itm2->setSelectionBrushImage(sel_img);
	cmb->addItem(itm2);

	CEGUI::ListboxTextItem* itm3;
	itm3 = new CEGUI::ListboxTextItem("FOG_LINEAR", 3);
	itm3->setSelectionBrushImage(sel_img);
	cmb->addItem(itm3);

	CEGUI::ListboxTextItem* itm4;
	itm4 = new CEGUI::ListboxTextItem("FOG_NONE", 0);
	itm4->setSelectionBrushImage(sel_img);
	cmb->addItem(itm4);


	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDayNightCycle");
	sld->setMaxValue(400);
	sld->setCurrentValue(1);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudSpeed");
	sld->setMaxValue(0.00005);
	sld->setCurrentValue(0.000005);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudsCover");
	sld->setMaxValue(1);
	sld->setCurrentValue(0.5);

	sld = (CEGUI::Slider*) CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudBendTime");
	sld->setMaxValue(48);
	sld->setCurrentValue(24);


	populateSkyBoxCombo();
	*/
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
bool frmScene::evtSceneClose_click(const CEGUI::EventArgs& e) {
	CEGUI::Window* w = CEGUI::WindowManager::getSingleton().getWindow("Scene");
	w->setVisible(false);
	return true;
}
bool frmScene::evtSceneBackgroundRed_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);

	//Ogre::ColourValue cv = GameSceneManager::getSingleton()->getViewport()->getBackgroundColour(); // setBackgroundColour(
	//cv.r = sld->getCurrentValue();
	sky_config.backgroundColour.r = sld->getCurrentValue();
	GameSceneManager::getSingleton()->getViewport()->setBackgroundColour(sky_config.backgroundColour);
	//sky_config.backgroundColour = cv;
	return true;
}
bool frmScene::evtSceneBackgroundGreen_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);

	Ogre::ColourValue cv = GameSceneManager::getSingleton()->getViewport()->getBackgroundColour(); // setBackgroundColour(
	//cv.g = sld->getCurrentValue();
	sky_config.backgroundColour.g = sld->getCurrentValue();
	GameSceneManager::getSingleton()->getViewport()->setBackgroundColour(sky_config.backgroundColour);
	//sky_config.backgroundColour = cv;
	return true;
}
bool frmScene::evtSceneBackgroundBlue_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);

	Ogre::ColourValue cv = GameSceneManager::getSingleton()->getViewport()->getBackgroundColour(); // setBackgroundColour(
	//cv.b = sld->getCurrentValue();
	sky_config.backgroundColour.b = sld->getCurrentValue();
	GameSceneManager::getSingleton()->getViewport()->setBackgroundColour(sky_config.backgroundColour);
	//sky_config.backgroundColour = cv;
	return true;
}


bool frmScene::updateFog() {

/*
	//const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Combobox* cmb = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbFogType");

	std::string fog_type_name = (std::string)cmb->getText().c_str();
	//unsigned int fog_type;
	Ogre::FogMode fog_type;
	
	//fog_type = NULL;

	if(fog_type_name == "FOG_EXP") {
		fog_type = Ogre::FOG_EXP;
		sky_config.FogType = 1;
	}

	if(fog_type_name == "FOG_EXP2") {
		fog_type = Ogre::FOG_EXP2;
		sky_config.FogType = 2;

	}

	if(fog_type_name == "FOG_LINEAR") {
		fog_type = Ogre::FOG_LINEAR;
		sky_config.FogType = 3;
	}

	if(fog_type_name == "FOG_NONE") {
		fog_type = Ogre::FOG_NONE;
		sky_config.FogType = 0;
	}

	if(fog_type_name == "") {
		fog_type = Ogre::FOG_NONE;
		sky_config.FogType = 0;
	}

	//fog density
	CEGUI::Slider* sld = (CEGUI::Slider*)CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogDensity");
	Ogre::Real density;
	density = sld->getCurrentValue();
	
	//Fog color red slider
	sld = (CEGUI::Slider*)CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogRed");
	//Ogre::ColourValue cv;
	sky_config.FogColour.r = sld->getCurrentValue();

	//Fog color red green
	sld = (CEGUI::Slider*)CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogGreen");
	sky_config.FogColour.g = sld->getCurrentValue();

	//Fog color red blue
	sld = (CEGUI::Slider*)CEGUI::WindowManager::getSingleton().getWindow("Scene/sldFogBlue");
	sky_config.FogColour.b = sld->getCurrentValue();

	CEGUI::Editbox* txtFogLineStart = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtFogLineStart");
	CEGUI::Editbox* txtFogLineEnd = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtFogLineEnd");
	
	Ogre::Real FogLineStart = atof(txtFogLineStart->getText().c_str());
	Ogre::Real FogLineEnd = atof(txtFogLineEnd->getText().c_str());
	
	//if(!fog_type || !cv || !density || !FogLineStart || !FogLineEnd )
	//	return false;

	GameSceneManager::getSingleton()->getSceneManager()->setFog(fog_type,sky_config.FogColour,density, FogLineStart,FogLineEnd);

	sky_config.FogLineStart = FogLineStart;
	sky_config.FogLineEnd = FogLineEnd;
	sky_config.FogDensity = density;
	//sky_config.FogColour = cv;

	//density 0.008
	//GameSceneManager::getSingleton()->getSceneManager()->getFogColour
*/

	return true;
}

void frmScene::populateSkyBoxCombo() {
	CEGUI::Combobox* cmbBox = (CEGUI::Combobox*) CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbSkybox");
	cmbBox->resetList();

	Ogre::MaterialManager::ResourceMapIterator mat = Ogre::MaterialManager::getSingleton().getResourceIterator();
	while(mat.hasMoreElements())
	{ 
		int i;
		i = 0;
		Ogre::MaterialPtr mat2 = static_cast<Ogre::MaterialPtr>(mat.getNext());
		Ogre::String groupName = mat2->getGroup(); //== "Sky"
		if(groupName == "Sky") {
			std::string matName = mat2->getName();
			string::size_type loc = matName. find("/",matName.length());
			std::string skyBox = matName.substr(0,4);
			
			if( skyBox == "Sky/" ) {
				std::string r = matName.substr(0,loc);
				
				const CEGUI::Image* sel_img = &CEGUI::ImagesetManager::getSingleton().getImageset("TaharezLook")->getImage("MultiListSelectionBrush");
				CEGUI::ListboxTextItem* item = new CEGUI::ListboxTextItem(matName,i);
				i++;
				item->setSelectionBrushImage(sel_img);
				cmbBox->addItem(item);
			}		
		}
	}
}


bool frmScene::evtSceneFogType_change(const CEGUI::EventArgs& e) {
	//updateFog();
	
	CEGUI::Combobox* cmb = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbFogType");

	std::string fog_type_name = (std::string)cmb->getText().c_str();

	//fog_type = NULL;

	if(fog_type_name == "FOG_EXP")
		sky_config.FogType = Ogre::FOG_EXP;
	
	if(fog_type_name == "FOG_EXP2")
		sky_config.FogType = Ogre::FOG_EXP2;
	
	if(fog_type_name == "FOG_LINEAR")
		sky_config.FogType = Ogre::FOG_LINEAR;
	
	if(fog_type_name == "FOG_NONE") 
		sky_config.FogType = Ogre::FOG_NONE;
	
	if(fog_type_name == "")
		sky_config.FogType = Ogre::FOG_NONE;
	
	GameSceneManager::getSingleton()->getSceneManager()->setFog(sky_config.FogType,sky_config.FogColour,sky_config.FogDensity,sky_config.FogLineStart,sky_config.FogLineEnd);

	return true;
}

bool frmScene::evtSceneFogDensity_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	
	CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblRed11");
	lbl->setText(StringConverter::toString(sld->getCurrentValue()));

	//updateFog();
	sky_config.FogDensity = sld->getCurrentValue();
	GameSceneManager::getSingleton()->getSceneManager()->setFog(sky_config.FogType,sky_config.FogColour,sky_config.FogDensity,sky_config.FogLineStart,sky_config.FogLineEnd);
	return true;
}
bool frmScene::evtSceneFogColorRed_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	
	CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblFogRedValue");
	lbl->setText(StringConverter::toString(sld->getCurrentValue()));

	//updateFog();
	sky_config.FogColour.r = sld->getCurrentValue();
	GameSceneManager::getSingleton()->getSceneManager()->setFog(sky_config.FogType,sky_config.FogColour,sky_config.FogDensity,sky_config.FogLineStart,sky_config.FogLineEnd);

	return true;
}
bool frmScene::evtSceneFogColorGreen_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	
	CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblFogGreenValue");
	lbl->setText(StringConverter::toString(sld->getCurrentValue()));

	//updateFog();
	sky_config.FogColour.g = sld->getCurrentValue();
	GameSceneManager::getSingleton()->getSceneManager()->setFog(sky_config.FogType,sky_config.FogColour,sky_config.FogDensity,sky_config.FogLineStart,sky_config.FogLineEnd);
	
	return true;
}
bool frmScene::evtSceneFogColorBlue_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	
	CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblFogBlueValue");
	lbl->setText(StringConverter::toString(sld->getCurrentValue()));

	//updateFog();
	sky_config.FogColour.b = sld->getCurrentValue();
	GameSceneManager::getSingleton()->getSceneManager()->setFog(sky_config.FogType,sky_config.FogColour,sky_config.FogDensity,sky_config.FogLineStart,sky_config.FogLineEnd);

	return true;
}
	
bool frmScene::evtSceneAmbientLightRed_change(const CEGUI::EventArgs& e) {

	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	
	if(sky_config.skyMode == "Skybox") {
		Ogre::ColourValue cv;
		//cv = GameSceneManager::getSingleton()->getSceneManager()->getAmbientLight();
		
		//cv.r = sld->getCurrentValue();
		sky_config.ambientLight.r = sld->getCurrentValue();

		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblAmbientLightRedValue");
		lbl->setText(StringConverter::toString(sld->getCurrentValue()));

		GameSceneManager::getSingleton()->getSceneManager()->setAmbientLight(sky_config.ambientLight);
	}
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		
		sky_config.ambientLight.r = (Ogre::Real)sld->getCurrentValue();
		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getSun()->setAmbientMultiplier(sky_config.ambientLight);
		
		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblAmbientLightRedValue");
		lbl->setText(StringConverter::toString(sky_config.ambientLight.r));
	}

	return true;
}
bool frmScene::evtSceneAmbientLightGreen_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	if(sky_config.skyMode == "Skybox") {
		Ogre::ColourValue cv;
		//cv = GameSceneManager::getSingleton()->getSceneManager()->getAmbientLight();
		
		//cv.g = sld->getCurrentValue();
		sky_config.ambientLight.g = sld->getCurrentValue();

		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblAmbientLightGreenValue");
		lbl->setText(StringConverter::toString(sld->getCurrentValue()));

		GameSceneManager::getSingleton()->getSceneManager()->setAmbientLight(sky_config.ambientLight);
	}
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		sky_config.ambientLight.g = (Ogre::Real)sld->getCurrentValue();
		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getSun()->setAmbientMultiplier(sky_config.ambientLight);

		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblAmbientLightGreenValue");
		lbl->setText(StringConverter::toString(sky_config.ambientLight.g));
	}
	
	return true;
}
bool frmScene::evtSceneAmbientLightBlue_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	if(sky_config.skyMode == "Skybox") {
		Ogre::ColourValue cv;
		//cv = GameSceneManager::getSingleton()->getSceneManager()->getAmbientLight();
		
		//cv.b = sld->getCurrentValue();
		sky_config.ambientLight.b = sld->getCurrentValue();

		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblAmbientLightBlueValue");
		lbl->setText(StringConverter::toString(sld->getCurrentValue()));

		GameSceneManager::getSingleton()->getSceneManager()->setAmbientLight(sky_config.ambientLight);
	}
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		sky_config.ambientLight.b = (Ogre::Real)sld->getCurrentValue();
		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getSun()->setAmbientMultiplier(sky_config.ambientLight);

		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblAmbientLightBlueValue");
		lbl->setText(StringConverter::toString(sky_config.ambientLight.b));
	}
	return true;
}

bool frmScene::evtSceneDiffuseLightRed_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		sky_config.diffuseLight.r = (Ogre::Real)sld->getCurrentValue();
		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getSun()->setDiffuseMultiplier(sky_config.diffuseLight);
		
		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblDiffuseRedValue");
		lbl->setText(StringConverter::toString(sky_config.diffuseLight.r));
	}
	return true;
}
bool frmScene::evtSceneDiffuseLightGreen_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	sky_config.diffuseLight.g = (Ogre::Real)sld->getCurrentValue();
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		
		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getSun()->setDiffuseMultiplier(sky_config.diffuseLight);
		
		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblDiffuseGreenValue");
		lbl->setText(StringConverter::toString(sky_config.diffuseLight.g));
	}
	return true;
}
bool frmScene::evtSceneDiffuseLightBlue_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	sky_config.diffuseLight.b = (Ogre::Real)sld->getCurrentValue();
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		
		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getSun()->setDiffuseMultiplier(sky_config.diffuseLight);
		
		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblDiffuseBlueValue");
		lbl->setText(StringConverter::toString(sky_config.diffuseLight.b));
	}
	return true;
}
bool frmScene::evtSceneSpecularLightRed_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	sky_config.specularLight.r = (Ogre::Real)sld->getCurrentValue();
	
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		
		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getSun()->setSpecularMultiplier(sky_config.specularLight);
		
		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblSpecularRedValue");
		lbl->setText(StringConverter::toString(sky_config.specularLight.r));
	}
	return true;
}

bool frmScene::evtSceneSpecularLightGreen_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	sky_config.specularLight.g = (Ogre::Real)sld->getCurrentValue();
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		
		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getSun()->setSpecularMultiplier(sky_config.specularLight);
		
		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblSpecularGreenValue");
		lbl->setText(StringConverter::toString(sky_config.specularLight.g));
	}
	return true;
}

bool frmScene::evtSceneSpecularLightBlue_change(const CEGUI::EventArgs& e) {
	const CEGUI::WindowEventArgs& wEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
	CEGUI::Slider* sld = static_cast<CEGUI::Slider*>(wEventArgs.window);
	sky_config.specularLight.b = (Ogre::Real)sld->getCurrentValue();
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		
		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getSun()->setSpecularMultiplier(sky_config.specularLight);
		
		CEGUI::Window *lbl = (CEGUI::Window*)CEGUI::WindowManager::getSingleton().getWindow("Scene/lblSpecularBlueValue");
		lbl->setText(StringConverter::toString(sky_config.specularLight.b));
	}
	return true;
}

bool frmScene::evtSceneDayNightCycle_change(const CEGUI::EventArgs& e) {
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		CEGUI::Slider* sld = (CEGUI::Slider*)CEGUI::WindowManager::getSingleton().getWindow("Scene/sldDayNightCycle");
		sky_config.timeScale = (Ogre::Real)sld->getCurrentValue();

		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getUniversalClock()->setTimeScale(sky_config.timeScale);
	}

	return true;
}

bool frmScene::evtSceneCloudsSpeed_change(const CEGUI::EventArgs& e) {
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		CEGUI::Slider* sld = (CEGUI::Slider*)CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudSpeed");
		sky_config.cloudsSpeed = (Ogre::Real)sld->getCurrentValue();

		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getClouds()->setCloudSpeed(Ogre::Vector2(sky_config.cloudsSpeed, -0.000009));
	}
	return true;
}

bool frmScene::evtSceneCloudsCover_change(const CEGUI::EventArgs& e) {
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		CEGUI::Slider* sld = (CEGUI::Slider*)CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudsCover");
		sky_config.cloudsCover = (Ogre::Real)sld->getCurrentValue();

		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getClouds()->setCloudCover(sky_config.cloudsCover);
	}
	return true;
}

bool frmScene::evtSceneCloudsBendTime_change(const CEGUI::EventArgs& e) {
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		CEGUI::Slider* sld = (CEGUI::Slider*)CEGUI::WindowManager::getSingleton().getWindow("Scene/sldCloudBendTime");
		sky_config.cloudsBendTime = (Ogre::Real)sld->getCurrentValue();

		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getClouds()->setCloudBlendTime(3600 * sky_config.cloudsBendTime);
	}

	return true;
}

bool frmScene::evtSceneActivateSky_click(const CEGUI::EventArgs& e) {
	GameSystemManager::getSingleton()->getGUI()->showLoader(true);
	if(sky_config.isLoaded) {
		//GameSystemManager::getSingleton()->getSky()->createSky();
		GameSystemManager::getSingleton()->getSky()->destroySky();
		sky_config.isLoaded = false;
	} else {
		//GameSystemManager::getSingleton()->getSky()->destroySky();
		sky_config.isLoaded = true;
		GameSystemManager::getSingleton()->getSky()->createSky();
	}
	GameSystemManager::getSingleton()->getGUI()->showLoader(false);
	return true;
}

bool frmScene::evtSceneManageLight_click(const CEGUI::EventArgs& e) {
	if (sky_config.skyMode == "Caelum" && sky_config.isLoaded) {
		sky_config.manageLights = GameSystemManager::getSingleton()->getGUI()->isCheckBoxSelected("Scene/chkLightManaged");
		GameSystemManager::getSingleton()->getSky()->mCaelumSystem->getSun()->setManageAmbientLight(sky_config.manageLights);
	}
	return true;
}

bool frmScene::evtSceneNearClip_change(const CEGUI::EventArgs& e) {
	CEGUI::Editbox* w = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtNearClipDistance");
	std::string nc = w->getText().c_str();
	Ogre::Real near_clip = atof(w->getText().c_str());
	GameSceneManager::getSingleton()->getCamera()->setNearClipDistance(near_clip);
	sky_config.NearClip = near_clip;
	return true;
}

bool frmScene::evtSceneAspectRatio_change(const CEGUI::EventArgs& e) {
	CEGUI::Editbox* w = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtAspectRatio");	
	Ogre::Real aspect_ratio = atof(w->getText().c_str());
	GameSceneManager::getSingleton()->getCamera()->setAspectRatio(aspect_ratio);
	sky_config.AspectRatio = aspect_ratio;
	return true;
}

bool frmScene::evtSceneFarClip_change(const CEGUI::EventArgs& e) {
	CEGUI::Editbox* w = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtFarClipDistance");
	Ogre::Real far_clip = atof(w->getText().c_str());
	GameSceneManager::getSingleton()->getCamera()->setFarClipDistance(far_clip);
	sky_config.FarClip = far_clip;
	return true;
}

bool frmScene::evtSceneProjectionType_change(const CEGUI::EventArgs& e) {
	CEGUI::Combobox* cmb = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbProjType");

	std::string txtProj_type = (std::string)cmb->getText().c_str();

	if(txtProj_type == "PERSPECTIVE") {
		sky_config.ProjType = Ogre::ProjectionType::PT_PERSPECTIVE;
	}

	if(txtProj_type == "ORTHOGRAPHIC") {
		sky_config.ProjType = Ogre::ProjectionType::PT_ORTHOGRAPHIC;
	}

	//sky_config.ProjType
	GameSceneManager::getSingleton()->getCamera()->setProjectionType(sky_config.ProjType);

	return true;
}
bool frmScene::evtSceneFOVy_change(const CEGUI::EventArgs& e) {
	CEGUI::Editbox* txtFOVy = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/FOVy");
	Ogre::Radian FOVy = Radian(Degree( Ogre::StringConverter::parseReal(txtFOVy->getText().c_str()) )) ;
	GameSceneManager::getSingleton()->getCamera()->setFOVy(FOVy);
	sky_config.FOVy = FOVy;
	return true;
}

bool frmScene::evtSceneSkyBoxList_change(const CEGUI::EventArgs& e) {
	CEGUI::Combobox* cmb = (CEGUI::Combobox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/cmbSkybox");
	std::string skyBoxName = (std::string)cmb->getText().c_str();

	sky_config.skyBoxName = skyBoxName;
	
	return true;
}
bool frmScene::evtSceneOptSkyBox_change(const CEGUI::EventArgs& e) {
	sky_config.skyMode = "Skybox";
	return true;
}
bool frmScene::evtSceneOptCaelum_change(const CEGUI::EventArgs& e) {
	sky_config.skyMode = "Caelum";
	return true;
}

bool frmScene::evtSceneSkyBoxDistance_change(const CEGUI::EventArgs& e) {
	CEGUI::Editbox* w = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtSkyBoxDistance");
	sky_config.skyBoxDistance = atof(w->getText().c_str());
	if(sky_config.skyMode == "Skybox" && sky_config.skyBoxName != "" )
		GameSceneManager::getSingleton()->getSceneManager()->setSkyBox(true,sky_config.skyBoxName,sky_config.skyBoxDistance);
	else
		GameSceneManager::getSingleton()->getSceneManager()->setSkyBox(false,sky_config.skyBoxName,sky_config.skyBoxDistance);

	return true;
}

bool frmScene::evtSceneFogStart_change(const CEGUI::EventArgs& e) {
	CEGUI::Editbox* w = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtFogLineStart");
	sky_config.FogLineStart = atof(w->getText().c_str());
	GameSceneManager::getSingleton()->getSceneManager()->setFog(sky_config.FogType,sky_config.FogColour,sky_config.FogDensity,sky_config.FogLineStart,sky_config.FogLineEnd);
	return true;
}
bool frmScene::evtSceneFogEnd_change(const CEGUI::EventArgs& e) {
	CEGUI::Editbox* w = (CEGUI::Editbox*)CEGUI::WindowManager::getSingleton().getWindow("Scene/txtFogLineEnd");
	sky_config.FogLineEnd = atof(w->getText().c_str());
	GameSceneManager::getSingleton()->getSceneManager()->setFog(sky_config.FogType,sky_config.FogColour,sky_config.FogDensity,sky_config.FogLineStart,sky_config.FogLineEnd);
	return true;
}


